fix(message-db): reconnect stale pooled connections dropped by the se…#3603
Open
kiku98 wants to merge 1 commit into
Open
fix(message-db): reconnect stale pooled connections dropped by the se…#3603kiku98 wants to merge 1 commit into
kiku98 wants to merge 1 commit into
Conversation
…rver Pooled Mysql2::Client connections were handed out without verifying they were still alive. A connection parked in the pool during a quiet period could be closed server-side once it idled past `wait_timeout`, and the next query on it raised "disconnected by the server because of inactivity". This error was not matched by the pool's reconnect guard, so it propagated up, aborted message processing and left queued messages stuck. - Ping each pooled connection on checkout; discard and replace it if the server has already closed it. - Broaden the dead-connection pattern to also match the inactivity / server-disconnect wording as defence-in-depth for connections that die mid-block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The MessageDB connection pool hands out pooled Mysql2::Client connections without checking they're still alive. A connection parked in the pool during a quiet period is closed server-side once it idles past MySQL's wait_timeout; the next query on it raises Mysql2::Error: The client was disconnected by the server because of inactivity. The pool's reconnect guard only matched /(lost connection|gone away|not connected)/i, so this error was re-raised instead of triggering a reconnect — aborting message processing and leaving queued messages stuck.
Fix
Ping each pooled connection on checkout; discard and replace it if the server has already closed it.
Broaden the dead-connection pattern to also match the inactivity / server-disconnect wording, as defence-in-depth for connections that die mid-block.